import { getBuyOrderList } from 'services/buy/order';

export default {

    namespace: 'buyOrderList',

    state: {
      list:{},
    },

    subscriptions: {
        setup ({ dispatch, history }) {
          history.listen((location) => {
            if (location.pathname === '/buy/order/orderList') {
              dispatch({
                type: 'getBuyOrderList',
                payload:{
                }
              })
            }
          })  
          
        }
    },
    effects : {
      *getBuyOrderList ({ payload }, { call, put }) {
        const orderList = yield call(getBuyOrderList, payload);
        yield put({
          type: 'save',
          payload:{
            list:orderList.data.list
          }
        })
      },
    },
    reducers : {
      save (state, action) {
        return {
          ...state,
          ...action.payload
        }
      },
    }

}
